/**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:ces.org.course.event</p>
 * <p>File:FileUploadListener.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 May 17, 2019 4:24:21 PM
 */
package ces.org.course.api.event;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import ces.org.course.api.entity.DictionaryEntity;
import ces.org.course.api.service.DictionaryService;
import cn.hutool.core.io.FileUtil;

/**
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date May 17, 2019 4:24:21 PM
 * @version 1.0.2019
 */
@Component
public class FileUploadListener {

	@EventListener()
	public void listener(final FileUploadEvent event) {
		System.out.println(event.getMessage().getMessage());
		
		if(trigger != null && trigger.equals("event")){
			System.out.println("当前配置为事项监听触发模式，监听到文件上传事件");
			String filepath = event.getMessage().getPath();
			if(filepath!=null&&!("").equals(filepath.trim())){
				File file = new File(event.getMessage().getPath());
				if(file!=null&&file.isFile()&&"xml".equals(FileUtil.extName(file))){
					service.put(DictionaryEntity.CACHE_KEY, file);
				}
			}
			
		}
		
	}
	
	// 监听类型
	@Value("${ces.dict.trigger}")
	private String trigger;
	@Autowired
	private DictionaryService service;
	
}
